SI649 F24 Altair Homework #4¶
Overview¶
We'll focus on maps and cartrographic visualization. In this lab, you will practice:
- Point Maps
- Symbol Maps
- Choropleth maps
- Interactions with maps
Lab Instructions¶
- Save, rename, and submit the ipynb file (use your username in the name).
- Complete all the checkpoints, to create the required visualization at each cell.
- Run every cell (do Runtime -> Restart and run all to make sure you have a clean working version), print to pdf, submit the pdf file.
- If you end up stuck, show us your work by including links (URLs) that you have searched for. You'll get partial credit for showing your work in progress.
In [79]:
import pandas as pd
import altair as alt
from vega_datasets import data
alt.data_transformers.disable_max_rows()
df = pd.read_csv('https://raw.githubusercontent.com/dallascard/si649_public/main/altair_hw4/airports.csv')
url = "https://raw.githubusercontent.com/dallascard/si649_public/main/altair_hw4/small-airports.json"
Visualization 1: Dot Density Map¶
Description of the visualization:
We want to visualize the density of small airports in the world. Each small airport is represented by a dot. The visualization has two layers:
- The base layer shows the outline of the world map.
- The point map shows different small airports.
- The tooltip shows the name of the airport.
Hint:
- How can we show continents on the map? Which object can be used from the json dataset ?
- How can we show only small airports on the map?
In [80]:
small_airports = df[df['type'] == 'small_airport']
# Load the world map data
world_map = alt.topo_feature(data.world_110m.url, 'countries')
# A base layer with the world map
base = alt.Chart(world_map).mark_geoshape(
fill='lightgrey',
stroke='white'
).transform_filter(
alt.datum.id != 10 # Ignore the South Antarctica
).properties(
width=800,
)
# Add the points for small airports
points = alt.Chart(small_airports).mark_circle(size=10, color='red').encode(
longitude='longitude_deg:Q',
latitude='latitude_deg:Q',
tooltip=['name:N', 'municipality:N']
)
final_map = base + points
final_map
Out[80]: